package com.System.service.PostImpl;

import com.System.Dao.BarDao;
import com.System.Dao.PostDao;
import com.System.pojo.DisFavor;
import com.System.pojo.Favor;
import com.System.pojo.User;
import com.System.service.Post;
import com.System.untils.SqlSessionFactoryUtils;
import com.cloudHouse.session.SqlSession;
import com.cloudHouse.session.SqlSessionFactory;

import java.util.List;

public class PostService implements Post {
    SqlSessionFactory sqlSessionFactory= SqlSessionFactoryUtils.getSqlSessionFactory();
    @Override
    public com.System.pojo.Post selectMyPost(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        com.System.pojo.Post post = mapper.selectMyPost(user);
        sqlSession.close();
        return post;
    }
    @Override
    public Favor hasFavor(Favor favor) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        Favor favor1 = mapper.hasFavor(favor);
        sqlSession.close();
        return favor1;
    }

    @Override
    public void likePost(Favor favor) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        mapper.likePost(favor);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void unLikePost(Favor favor) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        mapper.unLikePost(favor);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public com.System.pojo.Post selectLikeNumbers(com.System.pojo.Post post) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        com.System.pojo.Post post1 = mapper.selectLikeNumbers(post);
        sqlSession.close();
        return post1;
    }

    @Override
    public void updateLikeNumber(com.System.pojo.Post post) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        mapper.updateLikeNumber(post);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void deleteMyPost(com.System.pojo.Post post) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        mapper.deleteMyPost(post);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void addPost(com.System.pojo.Post post) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        mapper.addPost(post);
        sqlSession.commit();
        sqlSession.close();

    }

    @Override
    public com.System.pojo.Post selectOne(com.System.pojo.Post post) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);

        com.System.pojo.Post post1 = mapper.selectOne(post);
        sqlSession.close();
        return post1;
    }

    @Override
    public void updatePost(com.System.pojo.Post post) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        mapper.updatePost(post);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void addDisFavor(DisFavor disFavor) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        mapper.addDisFavor(disFavor);
        sqlSession.commit();
        sqlSession.close();

    }

    @Override
    public DisFavor hasDisFavor(DisFavor disFavor) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        DisFavor disFavor1 = mapper.hasDisFavor(disFavor);
        sqlSession.close();
        return disFavor1;
    }

    @Override
    public void deleteDisFavor(DisFavor disFavor) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        mapper.deleteDisFavor(disFavor);
        sqlSession.commit();
        sqlSession.close();

    }
}
